//extends 对泛型加以约束
type BaseType = string | number

function copy<T extends BaseType>(arg: T): T {
    return arg
}

copy(123)

// copy([])

// function getValue<T, K extends keyof T>(obj: T, key: K) {
//     return obj[key]
// }

function getValue(obj: {[propName: string]: any}, key: string) {
    return obj[key] || 'no'
}

const obj = {a: 1, b: 2}
// console.log(getValue(obj, 'd'))

//in
type MyReadOnly<T> = {
    readonly [P in keyof T]: T[P]
}

interface Obj {
    name: string
}

type Objj = MyReadOnly<Obj>

const user:Objj = {name: 'kaho'}
user.name = 'kk'

